﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using BRMC.IntelligentCommunity.IntelligentCommunity.Parkings;
using BRMC.IntelligentCommunity.Parkings.Devices.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BRMC.IntelligentCommunity.Parkings
{
 public   class DeviceAppService : AsyncCrudAppService<
           Device,
            DeviceList,
            long,
             GetDeviceInput,
            CreateDevice,
            UpdateDevice
            >
    {
        private readonly IRepository<Device, long> _repository;
        public DeviceAppService(IRepository<Device, long> repository) : base(repository)
        {

            _repository = repository;
        }
        protected override IQueryable<Device> CreateFilteredQuery(GetDeviceInput input)
        {
            return base.CreateFilteredQuery(input)
                .Where(c => c.ParkingId == input.ParkingId&&c.GuardId==input.GuardId);

        }

        public async Task<GetDeviceForEdtiOutput> GetParkingForEdit(NullableIdDto input)
        {
            Device device = null;
            if (input.Id.HasValue)
            {
                device = await _repository.GetAsync(input.Id.Value);
            }

            var output = new GetDeviceForEdtiOutput();

            output.DeviceEdit = device != null ? ObjectMapper.Map<DeviceEdit>(device) : new DeviceEdit();

            return output;
        }
    }
}
